<?php
require('config.php');
$language_link=$_GET['id'];
if($language_link != null && $language_link > 0 ) {
	$icon_like = modelLike::getObject($language_link);
	if(!$icon_like)redirectFront(index);
}else{
	redirectFront(index);
}
$html_name = $icon_like->url_rewriting.'-'.$language_link.'.html';

if(isset($_GET['title_debug']) && trim($_GET['title_debug'])!=''){
	$_SESSION['title_debug'] = $_GET['title_debug'];
	$title_debug = $_GET['title_debug'];
}
else {
	$title_debug='';
	unset($_SESSION['title_debug']);
}

$page = new rootLayoutPage();
$page->addStyleSheet('table_sorter.css');
$page->addJavaScript('jQuery.pagination.js');
$page->addStyleSheet('pagination.css');

//-- Menu Page ----------------------------------------------//
//--------Menu indicator--------------//

//************************//
$arr = array();
$getListUrlIconLike = modelLike::getListUrlIconLike($language_link);
foreach($getListUrlIconLike AS $key=>$Url){
	$arr[$Url->language_code]=$Url->url_rewriting.'-'.$Url->language_link.'.html';
}
$header = new layoutHeader();
$header->setArrayUrl($arr);
$page->setHeader($header);

$page->setBaliseTitle($icon_like->meta_title);
$page->setDescription($icon_like->meta_description);
$extension = filename_extension($_SERVER['REQUEST_URI']);
$page->setCanonical($html_name);

$xml = tmxTranslate('layoutFooter.xml', REP_XLAT_LAYOUT);

$tpl_file = 'like.tpl';
$Body = new flyLayout(REP_TPL . $tpl_file);
$Body->start();
$Body->setVariable('page_title',$icon_like->title);
	//****Pagination***********//

	if(isset($_GET["page"]) > 1) {
		$id_page = $_GET['page'];
	    $limit = (($id_page-1)*ITEM_PER_PAGE_REAL_ESTATE)." , ".ITEM_PER_PAGE_REAL_ESTATE;
	}else{
		$id_page = '';
	    $limit = '0 , '.ITEM_PER_PAGE_REAL_ESTATE;
	}
	$format = modelUploadFormat::getObject(FORMAT_PHOTO_LIST);
	$format_zoom = modelUploadFormat::getObject(FORMAT_PREVIEW_PHOTO_LIST);
	$listLocationAll = modelLike::getListIconLikeByID($language_link,$limit, $title_debug);
	$countlistLocation = modelLike::countgetListIconLikeByID($language_link);
	//echo $listLocationAll->size().'='.$countlistLocation->countall;
	if($listLocationAll->size() > 0){
		foreach($listLocationAll as $key => $location){
			$Body->resetList('location_photo');
			if($location->url_repertoire){
				if(file_exists($location->url_repertoire.$format->url_format.$location->nom_serveur) and isImageFileName($location->nom_serveur)){
					$fichier = modelUploadFile::getObject($location->id_fichier);
					list($width, $height, $type, $attr) = getimagesize($fichier->url_repertoire.$format->url_format.$fichier->nom_serveur);
					$url_image = $fichier->url_repertoire.$format->url_format.$fichier->nom_serveur;
					if(file_exists($location->url_repertoire.$format_zoom->url_format.$location->nom_serveur) and isImageFileName($location->nom_serveur)){
						$url_image_zoom = $fichier->url_repertoire.$format_zoom->url_format.$fichier->nom_serveur;
					}else{
						$url_image_zoom = REP_DESIGN.'noimage.jpg';
					}
					$Body->setVariable('src_photo',$url_image);
					$Body->setVariable('width',$width.'px');
					$Body->setVariable('height',$height.'px');
					$Body->setVariable('url_photo',$location->url_rewriting.'-'.$location->language_link.'.html');
					$Body->parseList('location_photo');
					$Body->showBlock('block_place_photo');
				}else{
					$Body->hideBlock('block_place_photo');
				}
			}else{
				$Body->hideBlock('block_place_photo');
			}
			
			$comma = array();
			$i = 0;
			if($location->length>0){
				$comma[$i] = $xml['label_length'].' '.$location->length.$xml['label_meter'] ;$i=$i+1;
			}
			if($location->width>0){
				$comma[$i] = $xml['label_width'].' '.$location->width.$xml['label_meter'] ;$i=$i+1;
			}
			if($location->size_building>0){
				$comma[$i] = $xml['label_area'].' '.$location->size_building.$xml['label_meter_square'] ;$i=$i+1;
			}
			if($location->length_land>0){
				$comma[$i] = $xml['label_land_length'].' '.$location->length_land.$xml['label_meter'] ;$i=$i+1;
			}
			if($location->width_land>0){
				$comma[$i] = $xml['label_land_width'].' '.$location->width_land.$xml['label_meter']  ;$i=$i+1;
			}
			if($location->size_land>0){
				$comma[$i] = $xml['label_land_area'].' '.$location->size_land.$xml['label_meter_square'] ;$i=$i+1;
			}
			if($location->bedrooms>0){
				$comma[$i] = $xml['label_bedrooms'].' '.$location->bedrooms ;$i=$i+1;
			}
			if($location->bathrooms>0){
				$comma[$i] = $xml['label_bathrooms'].' '.$location->bathrooms ;$i=$i+1;
			}
			$Body->setVariable('id_addr',$key);
			$count = count($comma);
			$string = '' ;
			foreach($comma AS $key => $c){
				$count==$key+1?$string.=$c:$string.=$c.', ';
			}
			$Body->setVariable('place_description',$string);
			//$Body->setVariable('_content',$location->content);
			$Body->setVariable('meta_title',$location->meta_title);
			$Body->setVariable('place_name',substr($location->name_place,0,50));
			//$Body->setVariable('map_address',nl2br($location->address));
			$Body->setVariable('_reference',$location->reference);
			$Body->setVariable('province',$location->name_province);
			//$Body->setVariable('district',$location->name_district);
		if($location->id_icon!="" and  $location->id_icon <=3)
							{
								if ($location->id_icon==1) {
								$Body->setVariable('src_photo_icon',ICON_LIKE);
								}
								elseif($location->id_icon==2) {
								$Body->setVariable('src_photo_icon',ICON_EXCLUSIVE_MANDATORY);
								}
								elseif($location->id_icon==3) {
								$Body->setVariable('src_photo_icon',ICON_GOOD_OPPORTUNITY);
								}
							$Body->showBlock('rooftop_icon');
							}else{
								$Body->setVariable('src_photo_icon','noimage.jpg');
								$Body->hideBlock('rooftop_icon');
							}

			$Body->setVariable('price_sell',$location->price_sell<>0?number_format($location->price_sell,0,'.',' ').' '.CURRENCY:'');
			$Body->setVariable('price_rental',$location->price_rental<>0?number_format($location->price_rental,0,'.',' ').' '.CURRENCY:'');

			$Body->setVariable('url_category_map', $location->url_rewriting.'-'.$location->language_link.'.html');
			$Body->parseList('list_category_map');


		}
		$Body->showBlock('icon_like');
	}else{
		$Body->showBlock('nohting');
	}
	/* include pagination**/

//******Rented and sold****//
$Body->stop();
$page->setBody($Body);
$page->display();

?>